
# grab the triangle from the file
#file = open("pe018-data.txt")
file = open("pe067-data.txt")
triangle = file.readlines()

# convert the list of strings to a list of a list of integers for each line
data = []
for row in triangle:
    rowInt = []
    row = row.split(" ")
    for value in row:
        rowInt.append(int(value))
        
    data.append(rowInt)

del file
del triangle
del rowInt
del row

data = data[::-1] # go top down

maxsums = [data[0]] # first row is easy

for rowindex in range(1,len(data)):
    nextrow = []
    for cellindex in range(1, len(data[rowindex-1])):
        nextrow.append(
            max(maxsums[rowindex-1][cellindex-1],
                maxsums[rowindex-1][cellindex])
            +
            data[rowindex][cellindex-1]
        )
    maxsums.append(nextrow)

print 'The answer to Problem #18/67 is >>', maxsums[-1], '<<'